package corewarsxxi.logic;

import java.io.Serializable;

/**
 *
 * @author ei10139
 */
public abstract class AddressingMode implements Serializable
{
    /**
     * Calculates the value according to the current state of the memory array.
     * @param value     the value.
     * @param aField    look into either A-Field of B-Field.
     * @return          the value from Cores memory.
     */
    public abstract int getValue(int value, boolean aField);

    /**
     * Makes use of the Singleton pattern and returns the public static object.
     * @return it<i>self</i>.
     */
    public abstract AddressingMode getSelf();

    /**
     * All AddressingModes subclasses return strings with the length of 2 when
     * calling toString. This function returns only the character that corresponds
     * to either A-Field or the B-Field.
     * @param aField    A-Field symbol or B-Field
     * @return a 1-sized string with the corresponding symbol
     */
    public String toString(boolean aField)
    {
        return aField? this.toString().substring(0, 1)
                    :  this.toString().substring(1, 2);
    }
}